package com.example.chatroom.listener;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class HWSessionListener implements HttpSessionListener {

    private int onlineUserCount;


    @Override
    public void sessionCreated(HttpSessionEvent se) {
        System.out.println("新用户上线了");
        onlineUserCount++;
        se.getSession().getServletContext().setAttribute("count", onlineUserCount);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        System.out.println("用户下线了");
        onlineUserCount--;
        se.getSession().getServletContext().setAttribute("count", onlineUserCount);
    }
}
